const template = require('./template')(__dirname + '/source/index.html')
import ReactDOMServer from 'react-dom/server'
import SSR from './source/server-main.js'
import React from 'react'

function contentssr(option) {
    return ReactDOMServer.renderToString(
        React.createElement(SSR.default, option)
    )
}

function getContent(localUrl) {
    return template({
        renderString: contentssr({
            location: localUrl
        })
    })
}

export default function () {
    return async function (ctx) {
        console.log(ctx.url)
        if (ctx.url) {
            ctx.body = getContent(ctx.url)
            return
        }
        ctx.body = getContent('/')
    }
}
